home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / tutorial / trac.zip / LESSON1 < prev    next >
Text File  |  1990-02-09  |  33KB  |  662 lines

  1.  
  2.  
  3.  
  4.         
  5.                           ELEMENTARY COMPUTER PROGRAMMING
  6.                                       Lesson 1
  7.         
  8.                                    Copyright 1990
  9.                            Castle Oaks Computer Services
  10.                                Post Office Box 36082
  11.                             Indianapolis, IN 46236-0082
  12.         
  13.         COMPUTER ORGANIZATION
  14.         
  15.         Each model of computer usually differs from every other model in 
  16.         many of its details.  However, all computers have the same general 
  17.         organization.  This organization is shown in Figure I-1.
  18.         
  19.                                    +---------+
  20.                             +<<<<<<| CONTROL |>>>>>>+
  21.                             v      +---------+      v
  22.                             v         v   ^  v      v
  23.                             v         v   |  v      v
  24.                         +-------+  +--------+v  +--------+
  25.                         | INPUT |->| MEMORY |-->| OUTPUT |
  26.                         +-------+  +--------+v  +--------+
  27.                                       |   ^  v
  28.                                       v   |  v
  29.                                +-----------------+
  30.                                | ARITHMETIC UNIT |
  31.                                +-----------------+
  32.         
  33.                                    Figure I-1
  34.         
  35.         There are five major elements.  They are:
  36.         
  37.              a. MEMORY - This may consist of several types of memories 
  38.              which may be programmed to transfer data and/or instruc-
  39.              tions from one type (or part) of memory to another as 
  40.              required.  The single headed arrows in the figure indicate 
  41.              the normal flow of information between the memory and the 
  42.              other elements, and the lines of multiple arrows indicate 
  43.              the flow of control signals from the control unit to the 
  44.              other units.
  45.         
  46.              b. CONTROL - This unit calls instructions from the memory, 
  47.              decodes them, and controls all other elements in order to 
  48.              perform the required actions.  Note: The difference be-
  49.              tween a computer and a calculator is that a computer is a 
  50.              calculator that can store its instructions in its own 
  51.              memory.
  52.         
  53.              c. ARITHMETIC UNIT - This unit performs the necessary 
  54.              arithmetical and data manipulation operations.
  55.         
  56.              d. INPUT(s) - This unit may be a console keyboard, floppy 
  57.              disk, hard disk, etc.  There may be several of these.
  58.         
  59.         
  60.         
  61.                                       I-1
  62.  
  63.  
  64.              e. OUTPUT(s) - This unit may be a console screen, floppy 
  65.              disk, hard disk, printer, etc.  There may be several of 
  66.              these.  In most computers, the flow of data from input 
  67.              devices and to output devices is usually via the memory as 
  68.              shown in Figure I-1.
  69.         
  70.         A programmer working in a high level language, such as PASCAL, 
  71.         FORTRAN, BASIC, etc., need not know many of the details of the 
  72.         computer.  However, the basic organization, as outlined above, is 
  73.         useful in organizing a problem for computer solution.
  74.         
  75.         In order to learn more about how computers operate, it is best to 
  76.         limit the discussion by presenting the details of only one model of 
  77.         computer.  Once a person is familiar with the specifics of one 
  78.         particular model of computer, it is relatively easy to understand 
  79.         other models of computers, even more complex ones.  Therefore, in 
  80.         this course, we will discuss a particular computer that is not very 
  81.         complex.  The computer is called TRAC which is an acronym for TRAin-
  82.         ing Computer.  This computer does not exist in reality.  However, we 
  83.         will use a simulation of this computer which runs on an IBM PC 
  84.         compatible computer.  Using that simulator, we will execute TRAC 
  85.         programs as if they were running on a real TRAC.  In the next les-
  86.         son, we will cover the material you need to know to execute a TRAC 
  87.         program.  In this lesson, we will cover the attributes of TRAC and 
  88.         how to program it in its own machine language.
  89.         
  90.         TRAC has the same general hardware configuration as other computers.  
  91.         Some of the specifics are shown in Figure I-2.
  92.         
  93.                             +----------------------+ 
  94.                             |        CONTROL       |                 
  95.                       +<<<<<|   (P register is 4   |>>>>>>>>>>>>>+  
  96.                       v     |   decimal digits, I  |             v   
  97.                       v   +<| register is 7 digits |>>>>>>>>>+   v  
  98.                       v   v +----------------------+         v   v   
  99.                       v   v      v            ^              v_  v  
  100.                       v   v      v            |             /  | v   
  101.                       v_  v      v            |            /   | v  
  102.                      /  | v +----------------------+    __/    | v   
  103.                     /   | v |        MEMORY        |-->|Console| v  
  104.                  __/    | v |  2000 decimal words  |   +-------+ v   
  105.                 |Console|-->|    Each word is 9    |   +-------+ v  
  106.                 +-------+ v |   digits plus sign   |-->|Printer|<+   
  107.                           v +----------------------+   +-------+    
  108.                           v      |            ^        
  109.                           v      |            |   
  110.                           v      v            |   
  111.                           v +----------------------+
  112.                           +>|   ARITHMETIC UNIT    |
  113.                             |(Accumulator is 9     |
  114.                             |     digits plus sign)|
  115.                             +----------------------+
  116.         
  117.                                    Figure I-2
  118.         
  119.         
  120.         
  121.                                       I-2
  122.  
  123.  
  124.         The specifics for each of the five categories of elements is as 
  125.         follows:
  126.         
  127.              a. MEMORY - The memory consists of 2000 words whose ad-
  128.              dresses range from 0000 to 1999.  Any other addresses, if 
  129.              used, will cause unpredictable results (including the 
  130.              possibility of "locking up" the PC).  Each word is 9 
  131.              decimal digits (plus sign) in length.  A word may contain 
  132.              either a numeric value or an instruction.
  133.         
  134.              b. CONTROL - The control unit calls instructions from 
  135.              memory, decodes them, and controls all other elements to 
  136.              perform the required actions.  The control unit contains a 
  137.              4 decimal digit register called the P register which 
  138.              contains the memory address of the current instruction.  
  139.              The value in the P register is called the "location" of 
  140.              the instruction.  Normally after each instruction is 
  141.              executed, the P register automatically increments by one.  
  142.              Therefore, consecutive instructions usually reside in 
  143.              consecutive memory locations.  (In the discussion of the 
  144.              instruction repertoire, means for altering the sequence of 
  145.              instructions will be discussed.)  The control unit also 
  146.              contains a 7 decimal digit register called the I register 
  147.              which contains the current instruction.  The I register 
  148.              consists of three parts as illustrated in Figure I-3.
  149.         
  150.                                 +-+-+-+-+-+-+-+
  151.                                 | | | | | | | |
  152.                                 +-+-+-+-+-+-+-+
  153.                                  ^ ^ ^ ^     ^
  154.                                  ^ ^-^ ^-----^
  155.                                  ^  ^     ^
  156.                                  |  |     |
  157.                                  T  O     A
  158.                                  a  p     d
  159.                                  g        d
  160.                                     c     r
  161.                                     o     e
  162.                                     d     s
  163.                                     e     s
  164.         
  165.                                   Figure I-3
  166.         
  167.              The first digit of the I register is called the "TAG" 
  168.              field and may contain any single decimal digit.  Its use 
  169.              will be discussed under the subject "Index registers".  
  170.              For most instructions, this field will be blank or zero.
  171.         
  172.              The next two digits contain the operation code.  This 
  173.              specifies the operation to be performed.  Only certain 
  174.              operations are available.  Each available operation will 
  175.              be discussed in the section on operations.  Each operation 
  176.              requires an operand.  That is, something to be operated 
  177.              on, to, or with.
  178.         
  179.         
  180.         
  181.                                       I-3
  182.  
  183.  
  184.              The last four digits of the I register contains the memory 
  185.              address of the operand.  The operand field is also re-
  186.              ferred to as the address field.  It is usually the address 
  187.              of a memory location that contains a value to be operated 
  188.              on.  In shift operations, this field gives the amount to 
  189.              shift rather than a memory address.  In branch operations, 
  190.              this field gives an alternative memory location for chang-
  191.              ing the sequence of instructions being performed.  The 
  192.              address field will be explained more fully in the discus-
  193.              sions of operations and index registers.
  194.         
  195.              c. ARITHMETIC UNIT - This unit consists of one 9 decimal 
  196.              digit (plus sign) register called the A register (or 
  197.              accumulator).  It can perform the elementary operations of 
  198.              addition, subtraction, multiplication, and division.  
  199.              Other data manipulations can also be performed in the A 
  200.              register.  These and the arithmetic operations will be 
  201.              discussed in the section on operations.
  202.         
  203.              d. INPUT - TRAC has only one input device.  This device is 
  204.              the console keyboard and only numeric data may be entered.  
  205.              The specifics of the input data format will be discussed 
  206.              in the section on operations.
  207.         
  208.              e. OUTPUTS - TRAC has two output devices.  One device is 
  209.              the console screen and the other is the printer.
  210.         
  211.         OPERATIONS
  212.         
  213.         For ALL instructions, the control unit fetches the contents of the 
  214.         memory location specified by the address field of the I register.  
  215.         On some operations, this value is needed but on others it is not 
  216.         needed.  Since the given address (see note) is always accessed, it 
  217.         must always be a valid address.  
  218.         
  219.         (Note: The address may be an effective address, see discussion of 
  220.         index registers.)
  221.         
  222.         The actions for each operation code is given in the following.  For 
  223.         each operation, a two digit numeric operation code is given; and 
  224.         also, a two character mnemonic operation code is given in parenthe-
  225.         ses.  This is not required for machine language coding and can be 
  226.         ignored for the present.  It will be referred to in Lessons 3 and 4.
  227.         
  228.         00 (LD) LoaD the A register.  This operation causes the operand 
  229.                 (contents of the location specified by the address) to 
  230.                 replace the contents of the A register.
  231.         
  232.         01 (AD) ADd to the A register.  Causes the operand to be added to 
  233.                 the A register.  The sum replaces the previous contents of 
  234.                 the A register.  (The programmer must use care to avoid 
  235.                 causing an overflow.  TRAC will permit an overflow but it 
  236.                 will save only the least significant 9 digits and you will 
  237.                 NOT get an error message.)
  238.         
  239.         
  240.         
  241.                                       I-4
  242.  
  243.  
  244.         02 (SU) SUbtract from the A register.  Causes the operand to be 
  245.                 subtracted from the A register.  The difference replaces the 
  246.                 previous contents of the A register.  (The warning on over-
  247.                 flows applies to subtraction as well as addition.)
  248.         
  249.         03 (ST) STore the contents of the A register.  The contents of the A 
  250.                 register is stored at the location specified by the address.  
  251.                 The contents of the A register remain unchanged.
  252.         
  253.         15 (MU) MUltiply the A register by the operand.  The operand is the 
  254.                 multiplier and the contents of the A register is the multi-
  255.                 plicand.  The resulting product replaces the previous con-
  256.                 tents of the A register.  Since the contents of the A regis-
  257.                 ter can not exceed 9 decimal digits, the sum of the digits 
  258.                 in the multiplier and the multiplicand must not exceed 9.  
  259.                 (e.g. If the multiplier is a 4 digit number, then the multi-
  260.                 plicand may not have more than 5 digits.)  If this condition 
  261.                 is not satisfied, an overflow will occur and no error mes-
  262.                 sage is given.  An example program will be given later to 
  263.                 demonstrate how to obtain a full 18 digit product from two 9 
  264.                 digit factors.
  265.         
  266.         16 (DV) DiVide the A register by the operand.  The operand is the 
  267.                 divisor and the A register is the dividend.  The quotient 
  268.                 replaces the previous contents of the A register.  Since 
  269.                 this operation is division of one integer by another giving 
  270.                 only the integral part of the quotient (no rounding), there 
  271.                 can be no overflow as long as the divisor is non-zero.
  272.         
  273.         24 (BN) Branch on Negative.  The operand is the address itself.  If 
  274.                 the contents of the A register is negative, branch to the 
  275.                 location specified by the operand to obtain the next in-
  276.                 struction.  If the A register is zero or positive, obtain 
  277.                 the next instruction from the next consecutive location.
  278.         
  279.         25 (BZ) Branch on Zero.  The operand is the address itself.  If the 
  280.                 contents of the A register is zero, branch to the location 
  281.                 specified by the operand to obtain the next instruction.  If 
  282.                 the A register is non-zero, obtain the next instruction from 
  283.                 the next consecutive location.
  284.         
  285.         26 (BU) Branch Unconditionally.  The operand is the address itself.  
  286.                 Branch to the location specified by the operand to obtain 
  287.                 the next instruction.
  288.         
  289.         36 (SR) Shift Right.  The operand is the value of the effective 
  290.                 address.  Shift the contents of the A register right the 
  291.                 number of decimal places specified by the address.  Digits 
  292.                 shifted out of the right end of the A register are lost.  
  293.                 The positions vacated at the left end of the A register are 
  294.                 filled with zeroes.  The sign of the A register is pre-
  295.                 served.  Although right shifts of more than 9 places are 
  296.                 permissible, they have no utility.
  297.         
  298.         
  299.         
  300.         
  301.                                       I-5
  302.  
  303.  
  304.         37 (SL) Shift Left.  The operand is the value of the effective 
  305.                 address.  Shift the contents of the A register left the 
  306.                 number of decimal places specified by the address.  Digits 
  307.                 shifted out of the left end of the A register are lost.  The 
  308.                 positions vacated at the right end of the A register are 
  309.                 filled with zeroes.  
  310.         
  311.         40 (RD) ReaD input data.  This operation allows five values to be 
  312.                 read from the console keyboard into five consecutive memory 
  313.                 locations.  The first value is read into the location speci-
  314.                 fied by the address field; the next four are read into the 
  315.                 next four consecutive locations.  The address must not 
  316.                 exceed 1995.  When the program encounters the read command, 
  317.                 the console will display a '?' followed by a space and will 
  318.                 wait for the manual entry of up to five values.  The format 
  319.                 for entering data values is almost free-form.  Values are 
  320.                 entered as whole numbers (preceded by a '-', if negative) 
  321.                 and separated from each other by one or more spaces.  Each 
  322.                 value must not exceed 11 digits, including sign and spaces.  
  323.                 The entering of values is terminated by pressing the "ENTER" 
  324.                 key.  You must enter at least one value, even if zero.
  325.         
  326.         41 (PC) Print to Console.  This operation causes up to five values 
  327.                 to be displayed on the console screen.  The five values are 
  328.                 output from five consecutive memory locations beginning with 
  329.                 the memory location specified by the effective address.  The 
  330.                 effective address cannot exceed 1995.
  331.         
  332.         42 (PP) Print to printer.  This operation is identical to the previ-
  333.                 ous print command but the output is sent to the printer.
  334.         
  335.         50 (HT) HalT.  This operation stops the execution of the program.  
  336.                 ALL programs should be terminated with a halt command.  The 
  337.                 address has no meaning but it still must be a valid address.
  338.         
  339.         (Note: Any operation other than those given will give an error 
  340.         message, set the op code to 99, and continue.)
  341.         
  342.         INDEX REGISTERS
  343.         
  344.         TRAC has nine index registers.  These registers are numbered 1 
  345.         through 9 and are actually memory locations 0001 through 0009.  If 
  346.         you use any of these as index registers, you normally would avoid 
  347.         their use for instructions or constants.  The purpose of an index 
  348.         register is to provide a simple method of modifying an instruction.  
  349.         An index register is used by placing its number in the TAG field of 
  350.         the instruction to be modified.  When the TAG field is non-zero, the 
  351.         contents of the specified index register is added to the address of 
  352.         the instruction to give a new address called the effective address.  
  353.         The effective address must always be a valid machine address.
  354.         
  355.         Thus, if index register 2 contains the value, 3, the instruction:
  356.         
  357.                                 +-+-+-+-+-+-+-+
  358.                                 |2|0|1|1|0|0|4|
  359.                                 +-+-+-+-+-+-+-+
  360.         
  361.                                       I-6
  362.  
  363.  
  364.         would cause the contents of the memory location 1007 (1004 plus 3) 
  365.         to be added to the A register.  Or, in the case of the following 
  366.         shift operation:
  367.         
  368.                                 +-+-+-+-+-+-+-+
  369.                                 |2|3|6|0|0|0|1|
  370.                                 +-+-+-+-+-+-+-+
  371.         
  372.         the contents of the A register would be shifted right 4 (1 plus 3) 
  373.         places.
  374.         
  375.         EXAMPLE
  376.         
  377.         Convert an octal number (base 8) to decimal.  The flow chart of 
  378.         Figure I-4 provides a method for converting an octal number to 
  379.         decimal.  For those not familiar with numbers in bases other than 
  380.         10, the following explanation is given.  Suppose the number, 637 is 
  381.         given and it is identified as being in base 8.  The position of a 
  382.         digit in the number specifies that that digit is to be multiplied by 
  383.         a power of the base (in this case 8) in order to give its actual 
  384.         value.  In the example, the number represents 6 * 64 + 3 * 8 + 7.  
  385.         In decimal this would calculate to be 415.  Note that no digit of 
  386.         the number can be as great as the base.  Therefore, to convert a 
  387.         number from base 8, we must isolate each digit of the number, multi-
  388.         ply it by the appropriate power of 8 and then sum the individual 
  389.         products.  
  390.         
  391.         In the method illustrated, 
  392.         
  393.         we first enter the octal number that is to be converted.  
  394.         
  395.         Then we test to see if it is zero.  
  396.         
  397.         If it is we stop the program.  
  398.         
  399.         Next we determine if the number is positive or negative.  
  400.         
  401.         If it is negative, we must temporarily make it positive for the 
  402.         conversion.  Later we will change it back.
  403.         
  404.         Next we set an index register to 1 (this is for counting places)
  405.         
  406.         then we isolate the first (high order) digit and save it where the 
  407.         answer is developed.
  408.         
  409.         We then start a loop in which we multiply the partial answer by 8, 
  410.         isolate a digit, and add it to the partial result.
  411.         
  412.         The index is incremented and if it is less than 9, the loop is 
  413.         repeated.
  414.         
  415.         Otherwise, the sign is restored to the input value and the result 
  416.         and the answer are displayed.
  417.         
  418.         
  419.         
  420.         
  421.                                       I-7
  422.  
  423.  
  424.                                        |
  425.                                        v
  426.                                    ----------
  427.                      +----------->/ Read X /
  428.                      |            ---------
  429.                      |                 |
  430.                      |                 v
  431.                      |                / \ Equal  +------+
  432.                      |               <X:0>------>| HALT |
  433.                      |                \./        +------+
  434.                      |                 | Not equal
  435.                      |                 v
  436.                      | +--------+  >  / \ <   +--------+
  437.                      | | S = +1 |<---<X:0>--->| S = -1 |
  438.                      | +--------+     \./     | X = -X |
  439.                      |      |                 +--------+
  440.                      |      v                     v
  441.                      |     +------------------------+
  442.                      |     |         I = 1          |
  443.                      |     | Shift X right 8 places |
  444.                      |     |   Store result at Y    |
  445.                      |     +------------------------+
  446.                      |                 |
  447.                      |                 v
  448.                      |     +------------------------+
  449.                      |     |       Y = Y * 8        |
  450.                      |  +->| Shift X left I places  |
  451.                      |  |  | Shift right 8 places   |
  452.                      |  |  |       Add to Y         |
  453.                      |  |  +------------------------+
  454.                      |  |              |
  455.                      |  |              v
  456.                      |  |        +-----------+
  457.                      |  |        | I = I + 1 |
  458.                      |  |        +-----------+
  459.                      |  |              |
  460.                      |  |              v
  461.                      |  |          <  / \
  462.                      |  +------------<I:9> 
  463.                      |                \./ 
  464.                      |                 | >=
  465.                      |                 v
  466.                      |           +-----------+
  467.                      |           | X = S * X |
  468.                      |           | Y = S * Y |
  469.                      |           +-----------+
  470.                      |                 |
  471.                      |                 v
  472.                      |           --------------
  473.                      +----------/ Display X,Y /
  474.                                 --------------
  475.         
  476.                                   Figure I-4
  477.         
  478.         
  479.         
  480.         
  481.                                       I-8
  482.  
  483.  
  484.         The code in Figure I-5 gives one way that the flow chart could be 
  485.         coded in TRAC.  Some variations of this code are possible and may 
  486.         even be better.  The example uses all the operations except divide 
  487.         and print to printer.
  488.         
  489.         Here are some additional features of the code that should be noted.  
  490.         The last line of a program must contain 9999 in the location field 
  491.         and the address of the first instruction of the program must appear 
  492.         in the address field.  
  493.         
  494.         Columns 1 through 4 are to contain the location of an instruction 
  495.         (or constant).
  496.         
  497.         Column 5 must be blank.
  498.         
  499.         Columns 6 through 15 are used for entering a constant or an instruc-
  500.         tion.  These columns are used differently for constants than they 
  501.         are for instructions.  Constants may be placed anyplace within these 
  502.         columns (no embedded blanks).  Instructions must also leave columns 
  503.         6, 7, and 8 blank.  The tag field is column 9, columns 10 and 11 are 
  504.         for the operation code, and columns 12 through 15 are used for the 
  505.         operand field.
  506.         
  507.         Column 16 should be blank.
  508.         
  509.         Columns 17 through 80 may be used for comments.  You are encouraged 
  510.         to include comments since it is very difficult to understand machine 
  511.         code without comments.  These comments are ignored by TRAC.
  512.         
  513.         
  514.         
  515.         
  516.         
  517.         
  518.         
  519.         
  520.         
  521.         
  522.         
  523.         
  524.         
  525.         
  526.         
  527.         
  528.         
  529.         
  530.         
  531.         
  532.         
  533.         
  534.         
  535.         
  536.         
  537.         
  538.         
  539.         
  540.         
  541.                                       I-9
  542.  
  543.  
  544.         
  545.            L      O   A
  546.            O      P   D
  547.            C      E   D
  548.                   R   R
  549.         0010     401000 Put X into 1000 (Sets 1001 - 1004 to zero)
  550.         0011     001000 Load accumulator with X
  551.         0012     250048 If X is zero jump to halt instruction
  552.         0013     240017 If X is negative, skip next 3 instructions     
  553.         0014     001501 Load +1                                        
  554.         0015     031502 Store at S (sign)                              
  555.         0016     260022 Branch unconditionally around next 5           
  556.         0017     001503 Load -1                                        
  557.         0018     031502 Store at S                                     
  558.         0019     001500 Load zero                                      
  559.         0020     021000 Subtract X (This makes a negative X positive)  
  560.         0021     031000 Store back at X                                
  561.         0022     001501 Load 1                                         
  562.         0023     030002 I=1 using index register 2                     
  563.         0024     001000 Load X                                         
  564.         0025     360008 Shift it right 8                               
  565.         0026     031001 Store at Y                                     
  566.         0027     001001 Load Y (Note this is the start of a loop)      
  567.         0028     151504 Multiply by 8                                  
  568.         0029     031001 Store at Y                                     
  569.         0030     001000 Load X                                         
  570.         0031    2370000 Shift left by I (Contents of register 2)       
  571.         0032     360008 Shift right 8 (This isolates an octal digit)   
  572.         0033     011001 Add previous Y                                 
  573.         0034     031001 Store back at Y                                
  574.         0035     000002 Load I                                         
  575.         0036     011501 Add 1                                          
  576.         0037     030002 Store at I                                     
  577.         0038     021505 Subtract 9 to see if done                      
  578.         0039     240027 If negative repeat loop                        
  579.         0040     001000 Load X                                         
  580.         0041     151502 Multiply by sign                               
  581.         0042     031000 Store at X                                     
  582.         0043     001001 Load Y                                         
  583.         0044     151502 Multiply by sign                               
  584.         0045     031001 Store at Y                                     
  585.         0046     411000 Print X, Y                                     
  586.         0047     260010 Branch back to start                           
  587.         0048     500000 Halt
  588.         1500          0 Zero
  589.         1501          1 One
  590.         1503         -1 Negative one
  591.         1504          8 Eight
  592.         1505          9 Nine
  593.         9999         10 End of code and starting location
  594.         
  595.                                 Figure I-5
  596.         
  597.         
  598.         
  599.         
  600.         
  601.                                       I-10
  602.  
  603.  
  604.         The following flow chart is exercise 1.  In this exercise, you are 
  605.         to read five values from your keyboard, sum them using an index 
  606.         register in a loop and then display the sum.  The program will keep 
  607.         prompting you for values until you enter a zero in the first posi-
  608.         tion.  Code this problem now and enter it into a file.  After com-
  609.         pleting lesson 2 you should try running the program to see if it 
  610.         functions correctly.
  611.         
  612.                                        |
  613.                                        v
  614.                         --------------------------------
  615.                    +-->/ Read X(0),X(1),X(2),X(3),X(4) /
  616.                    |   --------------------------------
  617.                    |                   |
  618.                    |                   v
  619.                    |                  / \
  620.                    |                 /   \ =   +------+
  621.                    |                <X(0):>--->| STOP |
  622.                    |                 \  0/     +------+
  623.                    |                  \./
  624.                    |                   | Not =
  625.                    |                   v
  626.                    |               +-------+
  627.                    |               | I = 0 |
  628.                    |               | S = 0 |
  629.                    |               +-------+
  630.                    |                   |
  631.                    |                   v
  632.                    |           +---------------+
  633.                    |           | S = S + A(I)  |<--+
  634.                    |           +---------------+   |
  635.                    |                   |           |
  636.                    |                   v           |
  637.                    |             +-----------+     |
  638.                    |             | I = I + 1 |     |
  639.                    |             +-----------+     |
  640.                    |                   |           |
  641.                    |                   v           |
  642.                    |                  / \  <       |
  643.                    |                 <I:5>---------+
  644.                    |                  \./
  645.                    |                   | >=
  646.                    |                   v
  647.                    |               ----------
  648.                    +--------------/ Print S /
  649.                                   ----------
  650.         
  651.                                  Exercise I-1
  652.         
  653.         Note: When an expression such as I:4 appears inside a diamond, this 
  654.         means that I and 4 are to be compared (usually by finding I-4) and 
  655.         then testing and branching according to the conditions shown on the 
  656.         flow chart.
  657.         
  658.         
  659.         
  660.         
  661.                                       I-11
  662.